//
//  ViewController.m
//  代码完成UI布局
//
//  Created by apple on 15/9/15.
//  Copyright (c) 2015年 戴维营. All rights reserved.
//

#import "ViewController.h"
#import "ColorView.h"

@interface ViewController ()

{
    ColorView *colorView;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

#if 0
    NSString *str = @"天王盖地虎";
    
    //根据字体计算容纳本段文字的矩形
    NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};
    
    CGSize size = [str sizeWithAttributes:dict];
    
    NSLog(@"%@",NSStringFromCGSize(size));
    
    //－－－－－－－－－－－－－－－－－
    
    //返回一个字符串在一个矩形中实际所占大小
    
    CGRect rect = [str boundingRectWithSize:CGSizeMake(100, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    
    NSLog(@"%@",NSStringFromCGRect(rect));
    
    NSLog(@"%f",rect.size.height / size.height);

#endif
    
    CGSize size = self.view.frame.size;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 20,size.width - 20 , 30)];
    
    label.text = @"任务详情";
    
    //居中对齐
    label.textAlignment = NSTextAlignmentCenter;
    
    //文字颜色；
    label.textColor = [UIColor whiteColor];
    
    //字体大小；
    label.font = [UIFont boldSystemFontOfSize:20];
    
    //背景颜色；
    label.backgroundColor = [UIColor greenColor];
    
    [self.view addSubview:label];
    
    
//    NSString *str = @"任务一：陪娜迦打游戏";

    UILabel *_aLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 90, size.width - 20, 20)];
    
    _aLabel.text = @"任务一：陪娜迦打游戏";
    
//    _aLabel.textColor = [UIColor blackColor];
    
    _aLabel.font = [UIFont boldSystemFontOfSize:15];
    
    [self.view addSubview:_aLabel];
    
    //－－－－－－－－－－－－－－－
    
    //彩色条
    
    colorView = [[ColorView alloc] initWithFrame:CGRectMake(10, 60, size.width - 20, 10)];
    
    colorView.layer.cornerRadius = 5;
    
    colorView.aLabel.backgroundColor = [UIColor greenColor];
    
    colorView.bLabel.backgroundColor = [UIColor orangeColor];
    
    colorView.cLabel.backgroundColor = [UIColor yellowColor];
    
    colorView.dLabel.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:colorView];
    
    
    //内容
    
    NSString *str = @"娜迦喜欢充当中路小学生，切记不要跟她一伙，否则坑死你！";
    
    NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:30]};
    
//    CGSize _size = [str sizeWithAttributes:dict];
    
    
    CGRect rect = [str boundingRectWithSize:CGSizeMake(size.width - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    

    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, size.width - 20, rect.size.height)];
    
    contentLabel.backgroundColor = [UIColor orangeColor];
    
    contentLabel.text =str;   //@"娜迦喜欢充当中路小学生，切记不要跟她一伙，否则坑死你！";
    
    contentLabel.font = [UIFont boldSystemFontOfSize:30];
    
    contentLabel.textColor = [UIColor whiteColor];
    
    contentLabel.numberOfLines = 0;
    
    [self.view addSubview:contentLabel];
    

    //添加图片
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"abc"]];
    
    imageView.frame = CGRectMake(10, 100 + rect.size.height, size.width - 20, 300);
                              
                              
    [self.view addSubview:imageView];
    

#if 0
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 80, size.width - 20, rect.size.height)];
    
    textField.text = str;
    
    textField.font = [UIFont boldSystemFontOfSize:30];
    
    textField.backgroundColor = [UIColor orangeColor];
    
    [self.view addSubview:textField];
    
#endif
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGRect rect = CGRectMake(50, 200, 50, 100);
    
    colorView.frame = rect;
    
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
